package com.dylan.历史.领扣;

/**
 * @Auther: ankang
 * @Date: 2019/2/22 20:27
 * @Description:
 */
public class $0058最后一个单词长度 {

    class Solution {
        public int lengthOfLastWord(String s) {
            int len = 0;
            boolean hasWord = false;
            for (int i = s.length() - 1; i >= 0; i--) {
                char c = s.charAt(i);
                if (c == ' ') {
                    if(hasWord) {
                        break;
                    }
                } else {
                    hasWord = true;
                    len++;
                }
            }
            return len;
        }
    }
}
